package com.module.TraceSource;

import java.util.HashMap;
import java.util.Map;

import base.util.ConstantUnit;
import base.util.Page;

import com.module.TraceSource.manager.TsCodeForRecordManager;
import com.module.TraceSource.vo.TsCodeForRecord;
import com.module.sys.LoginSession;


public class TsCodeForRecordService {
	
	/**
	 * 溯源信息管理列表查询
	 * @param tsCodeForRecord
	 * @param start
	 * @param limit
	 * @return
	 * @throws Exception
	 */
	public Page list(TsCodeForRecord tsCodeForRecord, Integer start, Integer limit)
			throws Exception {
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		TsCodeForRecordManager codemanager = TsCodeForRecordManager.getInstance();
		page = codemanager.listTsCodeForRecordPage(tsCodeForRecord,page);
		return page;
	}
	/**
	 * 删除溯源信息
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Map remove(Long id)throws Exception{       
		Map<String,Object> map = new HashMap<String,Object>();
		TsCodeForRecordManager codemanager = TsCodeForRecordManager.getInstance();
		map = codemanager.removeTsCodeForRecordById(id);
		return map;
		
	}	
	/**
	 *  保存、更新溯源信息
	 * @param tsCodeForRecord
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> save(TsCodeForRecord tsCodeForRecord)throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		TsCodeForRecordManager codeForRecordManager = TsCodeForRecordManager.getInstance();
		if(tsCodeForRecord.getId()>0){
			//更新
			map = codeForRecordManager.updateTsCodeForRecord(tsCodeForRecord);
		}else{
			//新增
			tsCodeForRecord.setOrgId(LoginSession.getOrgid());
			map = codeForRecordManager.addTsCodeForRecord(tsCodeForRecord);
		}
		return map;

	} 
	/**
	 * 绑定
	 * @param tsCodeForRecord
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> bindCode(TsCodeForRecord tsCodeForRecord)throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		TsCodeForRecordManager codeForRecordManager = TsCodeForRecordManager.getInstance();
		map = codeForRecordManager.bindCodeForTranceSource(tsCodeForRecord);
		return map;
	}
	/**
	 * 根据id查询溯源信息管理
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public TsCodeForRecord findById(Long id)throws Exception{
		TsCodeForRecord tsCodeForRecord = new TsCodeForRecord();
		TsCodeForRecordManager codeForRecordManager = TsCodeForRecordManager.getInstance();
		tsCodeForRecord = codeForRecordManager.findTsCodeForRecordById(id);
		return tsCodeForRecord;
	}
}
